package com.oktest.measure

import android.app.Application
import androidx.room.Room
import com.cali.libcore.base.ContextHolder
import com.cali.libcore.http.RetrofitManagement
import com.cali.libcore.util.preference.BeanPreference
import com.cali.libcore.util.preference.LongPreference
import com.cali.libcore.util.preference.StringPreference
import com.oktest.measure.db.room.AppRoomData
import com.oktest.measure.entity.Person
import com.oktest.measure.http.Api

/**
 * @Author hhh
 * @Date 2020/9/21
 */
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        ContextHolder.init(this)
        initRoom()
    }

    private fun initRoom() {
        roomDatabase = Room.databaseBuilder(this,AppRoomData::class.java,"roomMeasure")
            .fallbackToDestructiveMigration()
            .allowMainThreadQueries()
            .build()
    }

    companion object{
        lateinit var roomDatabase: AppRoomData
        var personInfo by BeanPreference(Person())
        var memberId :String by StringPreference
        var currentTaskId: Long by LongPreference

        fun currTask() = roomDatabase.homeTaskDao().query(currentTaskId.toString())
        fun taskIsReceived() = currTask()?.isReceived ?: false

        fun resetInfo() {
            personInfo = Person()
            memberId = ""
        }
    }
}